package com.cloudatum.service;

import com.cloudatum.utils.PushToApp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Map;

/**
 * 活动列表
 * Created by Administrator on 2015/11/9.
 */
@Service
public class ActivityListService {

    Logger logger = LoggerFactory.getLogger(ActivityListService.class);

    @Autowired
    private ActivityListMapper activityListMapper;

    public void sendNextActivity(){

        try {
            Map<String,Object> map = activityListMapper.getNextActivity();
            if (null != map) {
                map.remove("id");
                map.remove("isOver");
                Timestamp timestamp = (Timestamp) map.get("activityTime");
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                map.put("activityTime", simpleDateFormat.format(timestamp));
                PushToApp.push(map);
            }
        }catch (Exception  e){
            logger.error(" ==> 向app推送失败！Exception :{} , message :{} ", e.getClass(), e.getMessage());
        }
    }

    public void setActivityOver(String activityId) {
        activityListMapper.setActivityOver(activityId);
    }
}
